import bge
import bgl

scene = bge.logic.getCurrentScene()
controller = bge.logic.getCurrentController()

LMB         = controller.sensors["LMB"]
mouseOver   = controller.sensors["MouseOver"]
endGUI     = controller.actuators["endGUI"]

opt1 = scene.objects["GUI-opt1"]
opt2 = scene.objects["GUI-opt2"]


bge.suspend = True

def showHotspots(status):
    for hotspot in bge.hotspots:
        hotspot.visible = status


if bge.handles == True:
    opt1.text = "x"
else:
    opt1.text = ""

if bge.showHotspots == True:
    opt2.text = "x"
else:
    opt2.text = ""


for i in range (0,10):
    scene.objects["GUI-selCam.00" + str(i)].text= ""
    scene.objects["GUI-txtCam.00" + str(i)].text= ""

for entry in range (0, len(bge.cameras)):
    scene.objects["GUI-selCam.00" + str(entry)].text= ""
    scene.objects["GUI-txtCam.00" + str(entry)].text= "[   ] " + bge.cameras[entry].name
    

i = 0
for cam in bge.cameras:
    if cam.name == bge.MainScene.active_camera.name:
        activeCam = i
    i+=1
    
scene.objects["GUI-selCam.00" + str(activeCam)].text= "x"



    
if LMB.positive and  mouseOver.hitObject != None:
    if mouseOver.hitObject.name == "GUI-opt1button":
        if opt1.text == "":
            opt1.text = "x"
            bge.handles = True
        else:
            opt1.text = ""
            bge.handles = False

    if mouseOver.hitObject.name == "GUI-opt2button":
        if opt2.text == "":
            opt2.text = "x"
            bge.showHotspots = True
            showHotspots(True)
        else:
            opt2.text = ""
            bge.showHotspots = False
            showHotspots(False)

#Compact UI selection trick: use the object name as identifier

    if mouseOver.hitObject.name[0:9] == "GUI-light":
        for sun in bge.sun:
            bge.MainScene.objects[sun].energy = float(mouseOver.hitObject.name.split(".")[1])

    if mouseOver.hitObject.name[0:7] == "GUI-cam":
        selectedCam = int(mouseOver.hitObject.name.split(".")[1])

        #Only select available cameras            
        if selectedCam < len(bge.cameras):
            bge.MainScene.active_camera = bge.cameras[selectedCam]
            bge.suspend = False
    
                        